package com.kuaiditu.assistant.api.kdy_api.base;

import com.kuaiditu.assistant.api.xz_api.xz_encode.xz_http.FormBodyBuilderFactory;
import com.kuaiditu.assistant.util.LogUtil;

import java.util.Map;

/**
 * Created by Eenie on 2017/9/15.
 * Email: eeniework@gmail.com
 * Des:
 */

public class BaseSTRequest {


    private Object data;


    public static BaseSTRequest DEFAULT(Object data) {
        BaseSTRequest request = new BaseSTRequest();
        request.setData(data);
        return request;
    }


    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map<String, String> build() {
        return FormBodyBuilderFactory.create(this.data);
    }


    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : build().entrySet()) {
            sb.append(entry + "=" + entry.getValue() + "&");
        }
        if (sb.length() > 0) {
            return sb.substring(0, sb.length() - 1);
        }
        LogUtil.e(sb.toString());
        return sb.toString();
    }


}
